Skip to content

fix(relay): skip private relay addresses on networks this host is not on - #609

Open
Battlelamb wants to merge 1 commit into
ExaDev:mainfrom
Battlelamb:fix/relay-skip-unreachable-private
Open

Battlelamb wants to merge 1 commit into
ExaDev:mainfrom
Battlelamb:fix/relay-skip-unreachable-private

Conversation

@Battlelamb

Copy link
Copy Markdown

Problem

A relay offer lists every external address of the offering host (RelayServer binds 0.0.0.0 by default). selectRelay treats any RFC 1918 or link-local address as tier lan, whether or not the selecting host is on that network.

Setup where this shows up: two machines on one tailnet, on different physical networks. Machine A is a relay and offers ws://192.168.1.39:36937/, ws://172.18.0.1:36937/ (a Docker bridge) and ws://100.123.240.67:36937/ (its tailnet address). Machine B is on 10.34.16.0/23. B picks the lan address 192.168.1.39, which it cannot reach, and every start logs:

Error: agent-comms: ws dial timed out after 10000ms: ws://192.168.1.39:36937/

The tailnet address is reachable, but it is never chosen. After the failed dial, selectUrl excludes the whole offer and B falls back to the public hub.

Change

  • selectRelay takes an optional localNetworks input: the CIDRs of this host's interfaces. A private or link-local address outside every one of them is skipped in all tiers, so selection falls through to the reachable address. Here that is the tailnet address, in tier trusted.
  • localNetworkCidrs() builds the input from os.networkInterfaces(), and RelayRole.selectUrl passes it.
  • If localNetworks is not given, behaviour is unchanged, so the existing 10 conformance cases still pass as they are.

Tests

  • Added 2 conformance cases to function/relay-selection.json: an off-subnet private address is skipped in favour of the tailnet one, and an on-subnet private address is still chosen as lan. The manifest count goes from 10 to 12.
  • tsc --noEmit and eslint . are clean.
  • vitest run: 2846 passed and 3 failed. The 3 failures happen on main without this change too: pi-manifest-packed, web-console-route and web-server need the built package or web dist.

🤖 Generated with Claude Code

A relay offer lists every external address of the offering host. Relay
selection treated any RFC 1918 / link-local address as "lan", so a peer
reached over a tailnet always picked the offering host's home-LAN address
(for example 192.168.1.39) and timed out, even when the same offer carried
a reachable tailnet address.

selectRelay now takes the CIDRs of this host's own interfaces
(localNetworkCidrs) and skips a private address outside all of them in
every tier, so selection falls through to the reachable address. When
localNetworks is not given, behaviour is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings November 23, 2026 06:45

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The interface-CIDR guard rejects reachable off-subnet private relays, causing previously usable relays to fall back to the public hub without being attempted.

1 open issue
What changed in this PR

This PR updates relay selection to avoid choosing private addresses on networks absent from the host’s interface CIDRs, aiming to prevent unnecessary dial timeouts between machines on different networks.

Changes:

  • Adds optional local-network filtering while preserving existing behavior when omitted.
  • Passes host interface CIDRs into runtime relay selection.
  • Adds conformance cases for off-subnet filtering and on-subnet preference.
File Description
src/​test/​conformance-functions.helper.ts Passes optional network CIDRs into conformance calls.
src/​core/​relay-selection.ts Collects interface CIDRs and filters off-subnet private addresses.
src/​core/​relay-role.ts Supplies host networks during relay selection.
conformance/​manifest.json Updates the relay-selection case count to 12.
conformance/​function/​relay-selection.json Adds off-subnet and on-subnet selection cases.

Review effort: Balanced

for (const address of offer.addresses) {
const host = relayHost(address);
if (host === undefined) continue;
if (isPrivateHost(host) && !onLocalNetwork(host, local)) continue;

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants